<template>
  <div class="header-info">
    <!--区域设置-->
    <div class="list-item-setting">
      <div class="title-info">
        <el-divider content-position="left">区域设置</el-divider>
      </div>
      <el-form-item label="区域高度">
        <el-input-number
            :min="0"
            size="small"
            v-model="optionsInfo.headHeight"
        />
      </el-form-item>
      <el-form-item label="背景颜色">
        <el-color-picker
            size="small"
            show-alpha
            :predefine="predefineColors"
            v-model="optionsInfo.backgroundColor"
        />
      </el-form-item>
      <el-form-item label="边框颜色">
        <el-color-picker
          size="small"
          show-alpha
          :predefine="predefineColors"
          v-model="optionsInfo.areaBorColor"
        />
      </el-form-item>
      <el-form-item label="视图模式" v-if="optionsInfo.docInfoMode">
        <el-select
            v-model="optionsInfo['docInfoMode']"
            placeholder="请选择"
            @change="handleChangeView"
        >
          <el-option
              v-for="item in docInfoModeOptions"
              :key="item.value"
              :label="item.label"
              :value="item.value"
          />
        </el-select>
      </el-form-item>
    </div>
    <!--科室设置-->
    <div class="list-item-setting">
      <div class="title-info">
        <el-divider content-position="left">科室(号别)设置显示</el-divider>
      </div>
      <el-form-item label="背景颜色">
        <el-color-picker
          size="small"
          show-alpha
          :predefine="predefineColors"
          v-model="optionsInfo.deptAreaBgColor"
        />
      </el-form-item>

      <el-form-item label="科室隐藏" v-if="false">
        <el-switch v-model="optionsInfo.deptHide" @change="handleDept"/>
      </el-form-item>
        <el-form-item label="科室(号别)字体颜色">
          <el-color-picker
            size="small"
            show-alpha
            :predefine="predefineColors"
            v-model="optionsInfo.deptColor"
          />
        </el-form-item>
        <el-form-item label="科室(号别)字体大小">
          <el-input-number
            :min="0"
            size="small"
            v-model="optionsInfo.deptFontsize"
          />
        </el-form-item>
      <el-form-item label="诊室隐藏" v-if="false">
        <el-switch v-model="optionsInfo.roomHide" :disabled="true"/>
      </el-form-item>

      <el-form-item label="是否跟随患者科室" class="follow-dept" v-if="false">
        <el-switch
            v-model="optionsInfo.followDept"
            @change="handleFollowDept"
        />
      </el-form-item>
      <el-form-item
          label="科室号别设定"
          class="dept-number-room-set"
          v-if="!optionsInfo.checkListOnoff"
      >
        <el-checkbox-group
            v-if="topOptions && topOptions.length"
            v-model="optionsInfo.checkList"
        >
          <el-checkbox
              v-for="item in topOptions"
              :label="item.value"
              :key="item.value"
              :disabled="item.value === 3"
              @change="(e) => handleChange(e, item)"
          >
            {{ item.label }}
          </el-checkbox>
        </el-checkbox-group>
      </el-form-item>
      <!--诊室选中字段-->
      <template v-if="optionsInfo['checkList'].includes(3)">
        <roomNameKeyEditor
            :designer="designer"
            :selected-widget="selectedWidget"
            :option-model="optionModel"
        />
      </template>

      <el-form-item label="诊室信息反置" v-if="false">
        <el-switch v-model="optionsInfo.roomeInfoReverse" :disabled="!(optionsInfo.checkList.length===2)"/>
      </el-form-item>
      <el-form-item label="诊室字体颜色">
        <el-color-picker
          size="small"
          show-alpha
          :predefine="predefineColors"
          v-model="optionsInfo.roomColor"
        />
      </el-form-item>
      <el-form-item label="诊室字体大小">
        <el-input-number
          :min="0"
          size="small"
          v-model="optionsInfo.roomFontsize"
        />
      </el-form-item>
      <el-form-item label="科室(号别)&诊室位置反置" class="follow-dept">
        <el-switch
            v-model="optionsInfo.deptRoomPosition"
            :disabled="
              optionsInfo &&
              optionsInfo.checkList &&
              optionsInfo.checkList.length === 1
            "
        />
      </el-form-item>

      <template v-if="optionsInfo.checkList.includes(2) &&!!(registerObjNameOptions?.length)">
        <div class="title">
          <el-divider content-position="center">号别信息</el-divider>
        </div>
        <el-form-item label="号别类型" class="register-info">
          <div class="options-info">
            <el-radio-group v-model="optionsInfo.registerObjNameKey">
              <el-radio
                  :label="item.dictValue"
                  :value="item.dictValue"
                  :key="item.dictValue"
                  v-for="item in registerObjNameOptions"
              >
                {{ item.dictLabel }}
              </el-radio>
            </el-radio-group>
          </div>
        </el-form-item>
        <el-form-item label="号别来源" class="register-info">
          <el-select
              v-model="optionsInfo['registerSource']"
              placeholder="请选择"
          >
            <el-option
                v-for="item in registerSourceOptions"
                :key="item.value"
                :label="item.label"
                :value="item.value"
                v-if="!item.disabled"
                :disabled="item.disabled"
            >
              {{ item.label }}
              <template v-if="!item.disabled">
                <el-tooltip
                    class="item"
                    effect="dark"
                    content="Bottom Center 提示文字"
                    placement="bottom"
                >
                  <div slot="content">
                    如果当前患者不存在则取当前医生关联的上一个就诊患者
                  </div>
                  <el-button class="tooltip-icon" v-if="item.value===2">
                    <i class="el-icon-warning"/>
                  </el-button>
                </el-tooltip>
              </template>
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item
            label="若无当前患者是否取关联科室的号别"
            class="follow-dept"
            v-if="optionsInfo['registerSource'] === 1 || optionsInfo['registerSource'] === 2"
        >
          <el-switch v-model="optionsInfo.relationRegister"/>
        </el-form-item>
      </template>
    </div>
    <!--医生设置-->
    <div class="list-item-setting" v-if="!optionsInfo.doctorConfig">
      <div class="title-info">
        <el-divider content-position="left">医生设置</el-divider>
      </div>
      <el-form-item label="二维码" v-if="optionsInfo['docInfoMode'] == 1">
        <el-switch
            v-model="optionsInfo.doctorCodeHide"
            :disabled="optionsInfo['docInfoMode'] == 1"
        />
      </el-form-item>

      <el-form-item label="医生显示设置" class="follow-dept">
        <el-select v-model="optionsInfo['doctorOrder']" placeholder="请选择">
          <el-option
              v-for="item in doctorShown"
              :key="item.value"
              :label="item.label"
              :value="item.value"
          >
          </el-option>
        </el-select>
      </el-form-item>

      <el-form-item
          label="医生名字粗细设置"
          class="follow-dept"
          v-if="optionsInfo.doctorFontWeight"
      >
        <el-select
            v-model="optionsInfo['doctorFontWeight']"
            placeholder="请选择"
        >
          <el-option
              v-for="item in fontWeightOptions"
              :key="item.value"
              :label="item.label"
              :value="item.value"
          >
          </el-option>
        </el-select>
      </el-form-item>
    </div>
    <!--候诊就诊设置-->
    <div class="list-item-setting" v-if="(optionsInfo?.widgetSign)!=='alone'">
      <div class="title-info">
        <el-divider content-position="left">候诊就诊设置</el-divider>
      </div>

      <el-form-item label="就诊患者">
        <el-input
            size="small"
            class="hide-spin-button"
            v-model="optionsInfo['currentPatientContent']"
        />
      </el-form-item>
      <el-form-item label="待诊患者">
        <el-input
            size="small"
            class="hide-spin-button"
            v-model="optionsInfo['waitingPatientContent']"
        />
      </el-form-item>
      <template v-if="!optionsInfo.waitingPatientHide">
        <el-form-item label="候诊类型设置" class="wait-patient-set">
          <el-radio-group
              v-model="optionsInfo.waitPatientType"
              @change="handleChangeType"
          >
            <el-radio
                :label="item.value"
                v-for="item in waitPatientTypeOptions"
                :key="item.value"
            >
              {{ item.label }}
            </el-radio>
          </el-radio-group>
        </el-form-item>
        <template v-if="optionsInfo.waitPatientType === 1">
          <el-form-item label="候诊就诊" class="wait-patient-set">
            <el-radio-group
                v-model="optionsInfo.waitMode"
                :disabled="optionsInfo.waitingPatientHide"
            >
              <el-radio
                  :label="item.value"
                  v-for="item in options"
                  :key="item.value"
              >
                {{ item.label }}
              </el-radio>
            </el-radio-group>
          </el-form-item>
        </template>
        <template v-if="optionsInfo.waitPatientType === 2">
          <el-form-item label="列表是否滚动">
            <el-switch v-model="optionsInfo.openScroll"/>
          </el-form-item>

          <el-form-item label="滚动速度">
            <el-input-number
                v-model="optionsInfo.waitPatientStep"
                :min="1"
                :max="4"
                size="small"
                class="hide-spin-button"
                :disabled="!optionsInfo.openScroll"
            />
          </el-form-item>

          <el-form-item label="候诊的人数">
            <el-input-number
                v-model="optionsInfo.waitPatientNumber"
                :min="1"
                :max="99"
                size="small"
                class="hide-spin-button"
            />
          </el-form-item>

          <el-form-item label="滚动的人数">
            <el-input-number
                v-model="optionsInfo.waitPatientScrollNumber"
                :min="4"
                :max="8"
                size="small"
                class="hide-spin-button"
                :disabled="!optionsInfo.openScroll"
            />
          </el-form-item>
        </template>
      </template>
    </div>


    <template v-if="(optionsInfo?.widgetSign)==='alone'">
      <el-form-item label="就诊患者字号" class="follow-dept">
        <el-input-number
            :min="12"
            size="small"
            v-model="optionsInfo.currenPatientFontSize"
        />
      </el-form-item>
      <el-form-item label="候诊患者字号" class="follow-dept">
        <el-input-number
            :min="12"
            size="small"
            v-model="optionsInfo.waitPatientFontSize"
        />
      </el-form-item>
    </template>

    <template v-if="optionsInfo['layerNameKey'] === 'room-call-patient'">
      <div
          class="list-item-setting"
          v-for="(item, index, key) in optionsInfo['layerInfo']"
          :key="index"
      >
        <div class="title-info">
          <el-divider content-position="left">{{
              index === "current" ? "就诊弹层设置" : "候诊弹层设置"
            }}
          </el-divider>
        </div>
         <el-form-item label="标题">
          <el-input
            v-model="optionsInfo['layerInfo'][index].content"
            placeholder="请输入内容"
            size="small"
          />
        </el-form-item>
         <el-form-item label="显示">
          <el-switch v-model="optionsInfo['layerInfo'][index]['display']" />
        </el-form-item>
         <el-form-item label="字号">
          <el-input-number
            :min="14"
            size="small"
            class="hide-spin-button"
            v-model="optionsInfo['layerInfo'][index].fontSize"
          />
        </el-form-item>
        <el-form-item label="背景颜色">
          <el-color-picker
              size="small"
              show-alpha
              :predefine="predefineColors"
              v-model="optionsInfo['layerInfo'][index].backgroundColor"
          />
        </el-form-item>
        <el-form-item label="标题字体色">
          <el-color-picker
              size="small"
              show-alpha
              :predefine="predefineColors"
              v-model="optionsInfo['layerInfo'][index].color"
          />
        </el-form-item>
        <el-form-item label="内容字体色">
          <el-color-picker
              size="small"
              show-alpha
              :predefine="predefineColors"
              v-model="optionsInfo['layerInfo'][index].patientColor"
          />
        </el-form-item>
      </div>
    </template>
    <div class="">
      <div class="title-info">
        <el-divider content-position="left">底部提示</el-divider>
      </div>
      <el-form-item label="提示内容">
        <el-input
            type="textarea"
            v-model="optionsInfo['noticeTips']"
        />
      </el-form-item>
      <el-form-item label="背景颜色">
        <el-color-picker
          size="small"
          show-alpha
          :predefine="predefineColors"
          v-model="optionsInfo.noticeTipsBgColor"
        />
      </el-form-item>
      <el-form-item label="字体色">
        <el-color-picker
          size="small"
          show-alpha
          :predefine="predefineColors"
          v-model="optionsInfo.noticeTipsColor"
        />
      </el-form-item>
      <el-form-item label="字体">
        <el-input-number
          :min="14"
          size="small"
          class="hide-spin-button"
          v-model="optionsInfo.noticeTipsFontSize"
        />
      </el-form-item>
    </div>
    <!--云医院二维码设置-->
    <div class="list-item-setting" v-if="optionsInfo['docInfoMode'] && optionsInfo['docInfoMode'] == 1">
      <div class="title-info">
        <el-divider content-position="left">医院信息设置</el-divider>
      </div>
      <el-form-item label="二维码" class="logo-area-set">
        <el-button
            type="primary"
            @click="handleSelect('hospitalCode', optionsInfo.hospitalCode)"
        >
          医院二维码
        </el-button>
        <div class="picture-wrap">
          <template
              v-if="
              !!(
                !!optionsInfo?.hospitalCode &&
                !!optionsInfo?.hospitalCode?.length &&
                !!optionsInfo?.hospitalCode[0].url
              )
            "
          >
            <img
                :src="`${optionsInfo.hospitalCode[0]?.url}`"
                alt="医院信息"
            />
            <p class="icon-wrap" @click="handleDeletePicture('hospitalCode')">
              <i class="el-icon-close icon-delete"/>
            </p>
          </template>
          <template v-else>
            <div
                class="el-upload el-upload--text"
                @click="handleSelect('hospitalCode', optionsInfo.hospitalCode)"
            >
              <i class="el-icon-plus avatar-uploader-icon"/>
            </div>
          </template>
        </div>
      </el-form-item>
      <el-form-item label="提示内容">
        <el-input
          type="textarea"
          v-model="optionsInfo['hosCodeTips']"
        />
      </el-form-item>
      <el-form-item label="字体色">
        <el-color-picker
          size="small"
          show-alpha
          :predefine="predefineColors"
          v-model="optionsInfo.hosCodeColor"
        />
      </el-form-item>
    </div>

    <!--选择图片的弹层-->
    <UpdatePicture
        :visible="pictureInfo.visible"
        :info="pictureInfo.info"
        @handleCancel="handleCancel"
        @handleSure="handleSure"
    />
  </div>
</template>

<script>
import constantDic from "@/utils/vue-i18n/lang/zh-CN";
import roomNameKeyEditor
  from "@sc/templateDetails/modules/homeRight/property-editor/module/scene-edit/basicInfo/roomNameKey-editor.vue";
import UpdatePicture from "@c/public/layer/template/updatePicture/index.vue";
import * as types from "@c/public/form-designer/devType/datas-types";

export default {
  name: "DRCInfoOptions-editor",
  components: {UpdatePicture, roomNameKeyEditor},
  componentName: "DRCInfoOptions-editor",
  mixins: [],

  props: {
    designer: Object,
    selectedWidget: Object,
    optionModel: Object,
  },

  inject: ["serverFieldList", "getDesignerConfig"],

  data() {
    return {
      radio: 1,
      optionsInfo: Object(),
      options: [
        {
          value: 1,
          label: "叫1等1",
        },
        {
          value: 2,
          label: "叫1等2",
        },
        {
          value: 3,
          label: "叫1等3",
        },
        {
          value: 4,
          label: "叫1等4",
        },
        {
          value: 5,
          label: "叫1等5",
        },
        {
          value: 6,
          label: "叫1等6",
        },
      ],
      checkList: [],
      topOptions: [
        {
          value: 1,
          label: "科室",
        },
        {
          value: 2,
          label: "号别",
        },
        {
          value: 3,
          label: "诊室",
        },
      ],
      constantDic: constantDic,
      predefineColors: types["predefineColors"],
      waitPatientTypeOptions: [
        {
          value: 1,
          label: "诊室等候",
        },
        {
          value: 2,
          label: "候诊列表",
        },
      ],
      doctorShown: [
        {
          value: 1,
          label: "医生:顺序优先",
        },
        {
          value: 2,
          label: "医生:时间优先",
        },
      ],
      registerSourceOptions: [
        {
          value: 1,
          disabled: false,
          label: "当前医生所在科室号别",
        },
        {
          value: 2,
          disabled: false,
          label: "当前医生呼叫患者号别",
        },
      ],
      fontWeightOptions: types["fontWeightOptions"],
      docInfoModeOptions: [
        {
          value: 1,
          label: "视图一",
        },
        {
          value: 2,
          label: "视图二",
        }
      ],
      pictureInfo: {
        info: Object(),
        visible: false,
      },
      deptList: [
        {
          value: 'deptName',
          label: "医生科室",
        },
        {
          value: 'oldDeptName',
          label: "屏幕科室",
        },
        {
          value: 'oldDeptShortName',
          label: "屏幕科室简称",
        },
      ]
    };
  },

  computed: {
    registerObjNameOptions() {
      return this.$store.getters["templateDetails/getRegisterObjNameOptions"];
    },
  },

  methods: {
    // 视图模式
    handleChangeView(val) {
      if (val === 0) {
        this.optionsInfo.doctorCodeHide = true;
        this.optionsInfo.waitingPatientHide = false;
      }
    },

    handleDept(val) {
      if (val) {
        this.optionsInfo.followDept = false;
      }
    },

    handleChangeType(val) {
      if (val === 1) {
        this.optionsInfo.openScroll = false;
        this.optionsInfo.waitPatientStep = 1;
        this.optionsInfo.waitPatientScrollNumber = 6;
        this.optionsInfo.waitPatientNumber = 6;
      } else if (val === 2) {
        this.optionsInfo.waitMode = 1;
      }
    },

    // 科室诊室&号别--科室和好别不能共存
    handleChange(val, row) {
      let value = row.value;
      let {checkList} = this.optionsInfo;
      // 如果长度小于2 取消反置
      if (value?.length !== 2) {
        Reflect.set(this.optionsInfo, 'deptRoomPosition', false)
      }
      if (value === 1) {
        if (val) {
          this.$lodash.pull(checkList, 2);
        }
      }
      if (value === 2) {
        if (val) {
          this.$lodash.pull(checkList, 1);
        }
      }
    },

    handleFollowDept(val) {
      if (val) {
        this.optionsInfo.deptHide = false;
      }
    },

    // 选择图片
    handleSelect(val, content) {
      let params = Object();
      switch (val) {
        case "publicCode":
        case "hospitalCode":
          let content2 = !!(content?.length && content[0]?.url) ? content : "";
          Reflect.set(params, "updataType", val);
          Reflect.set(params, "type", "image");
          Reflect.set(params, "multiple", false);
          Reflect.set(params, "content", content2 || "");
          Reflect.set(this.pictureInfo, "visible", true);
          Reflect.set(this.pictureInfo, "info", params);
          break;
      }
    },

    // 删除图片
    handleDeletePicture(key) {
      Reflect.set(this.optionsInfo, key, "");
    },

    // 关闭弹层
    handleCancel() {
      Reflect.set(this.pictureInfo, "visible", false);
    },

    // 更新就的数据
    handleSure(valInfo) {
      let {key, val} = valInfo;
      Reflect.set(this.optionsInfo, key, val);
    },
  },

  watch: {
    // 组件的所有信息
    optionModel: {
      handler: function (val) {
        this.optionsInfo = val[val.config];
      },
      deep: true,
      immediate: true,
    },
  },
};
</script>


<style lang="scss" scoped>
//候诊&就诊等待
.wait-patient-set {
  display: flex;
  flex-direction: column;

  :deep(.el-form-item__label) {
    width: 100% !important;
  }

  :deep(.el-form-item__content) {
    margin-left: 0 !important;

    .el-radio-group {
      display: flex;
      flex-direction: column;

      .el-radio {
        padding: 10px 0;
      }
    }
  }
}

.follow-dept {
  display: flex;
  flex-direction: column;

  :deep(.el-form-item__label) {
    width: 100% !important;
    margin-bottom: 8px;
    @include fontWeight();
  }

  :deep(.el-form-item__content) {
    margin-left: 0 !important;
  }
}

//科室 诊室 号别
.dept-number-room-set {
  display: flex;
  flex-direction: column;

  :deep(.el-form-item__label) {
    width: 100% !important;
    margin-bottom: 8px;
    @include fontWeight();
  }

  :deep(.el-form-item__content) {
    margin-left: 0 !important;

    .el-checkbox-group {
      display: flex;
      flex-direction: column;
    }
  }
}

//号别简称
.register-info {
  :deep(.el-form-item__content) {
    margin-left: 1px !important;

    .title {
      width: 100%;
    }

    .el-radio-group {
      .el-radio {
        width: 100%;
        padding: 8px 0;
      }
    }
  }
}

//互联网医院
.logo-area-set {
  display: flex;
  position: relative;
  flex-direction: column;

  :deep(.el-form-item__label) {
    width: 100% !important;
    display: flex;
    @include fontWeight();
  }

  :deep(.el-form-item__content) {
    margin-left: 0 !important;

    .el-button {
      position: absolute;
      top: -30px;
      right: 0;
    }

    .picture-wrap {
      margin-top: 10px;
      position: relative;
      overflow: hidden;
      width: 108px;
      height: 108px;

      img {
        border-radius: 4px;
        overflow: hidden;
        width: 100%;
      }

      .icon-wrap {
        width: 20px;
        height: 20px;
        display: flex;
        align-items: center;
        align-self: center;
        justify-content: center;
        background: rgba(0, 0, 0, 0.4);
        position: absolute;
        top: 0;
        left: 0;
        cursor: pointer;
        border-radius: 0 0 100px 0;

        .icon-delete {
          font-weight: bold;
          color: rgba(255, 255, 255, 0.8);
        }
      }

      .el-upload {
        background-color: #fbfdff;
        border: 1px dashed #c0ccda;
        border-radius: 6px;
        box-sizing: border-box;
        width: 108px;
        height: 108px;
        cursor: pointer;
        line-height: 116px;
        vertical-align: top;

        &:hover {
          border-color: #409eff;
          color: #409eff;
        }

        .el-icon-plus {
          font-size: 1.25rem;
          color: rgba(0, 0, 0, 0.45);
        }
      }
    }
  }
}

.tooltip-icon {
  border: none;
  background: transparent;
  padding: 0 12px 0 12px;
  font-size: 18px;
  border-radius: 0;
  color: #e6a23c;
}
</style>
